<?php
class Company_m extends CI_Model{
	public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	//--get companies--//
	public function _get_companies($perpage, $offset){
		$query = $this->db->select()
						  ->from("company")
						  ->limit($perpage, $offset)
						  ->get();
		if($query){
			return $query->result_array();
		}else{
			return FALSE;
		}
	}
	
	//--count companies--//
	public function _count_companies(){
		$query = $this->db->select()
						  ->from("company")
						  ->get();
		if($query){
			$count = $query->num_rows();
			return $count;
		}else{
			return FALSE;
		}
	}
	
	//--get company name--//
	function _get_company_name($name){
		$query = $this->db->select("name")
						  ->from("company")
						  ->where("name", $name)
						  ->get();
		if($query){
			return $query;
		}else{
			return false;
		}
	}
	
	//--get company name except current company id
	function _get_name_except_current_name($id, $name){
		$query = $this->db->select("name")
						  ->from("company")
						  ->where("id <>", $id)
						  ->where("name", $name)
						  ->get();
		if($query){
			return $query;
			
		}else{
			return FALSE;
		}			 
	}
	
	
	
	
	
	//--get company information--//
	function _get_company_infor($id){
		$query = $this->db->select("id, name, description")
						  ->from("company")
						  ->where("id", $id)
						  ->get();
		if($query){
			return $query;
		}else{
			return false;
		}
	}
	//-- add company--//
	function add_company($data){
		$query = $this->db->insert("company", $data);
		if($query){
			return $query;
		}else{
			return FALSE;
		}
	}
	
	//--edit company--//
	function edit_company($id, $data){
		$query = $this->db->update("company", $data, array("id" => $id));
		if($query){
			return $query;
		}else{
			return FALSE;
		}
	}
	
	//--delete company--//
	function delete_company($id){
		$query = $this->db->delete("company", array("id" => $id));
		if($query){
			return $query;
		}else{
			return FALSE;
		}
	}
}